package com.le.tester.javaThink.fourth.concurrency;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * createTime：2021/10/20 16:20
 * description：继承自atomicInteger
 */
public class AtomicEvenGenerator extends IntGenerator {
    private AtomicInteger currentEvenValue = new AtomicInteger(0);

    //生成偶数,原子性通过atomicInteger来进行消除
    @Override
    public int next() {
        return currentEvenValue.addAndGet(2);
    }

    public static void main(String[] args) {
        EvenChecker.test(new AtomicEvenGenerator());
    }
}
